﻿using NAnt.Core.Attributes;
using NAnt.SVN.Util;

namespace NAnt.SVN.Tasks
{
    /// <summary>
    /// Implementation of the cleanup command.
    /// You can run this tasc with the svnlog tag in NAnt.
    /// $Id$
    /// </summary>
    [TaskName("svnlog")]
    sealed public class Log : SVNTask
    {
        #region Private Fields

        private int limit = 10;
        private bool mergeinfooutput = false;
        private bool verboseoutput = false;

        #endregion

        #region Public fields

        [TaskAttribute("limit", Required = false)]
        [Int32Validator(1,50)]
        public int Limit
        {
            get { return limit; }
            set { limit = value; }
        }

        [TaskAttribute("mergeinfo", Required = false)]
        [BooleanValidator()]
        public bool MergeInfoOutput
        {
            get { return mergeinfooutput; }
            set { mergeinfooutput = value; }
        }

        [TaskAttribute("verbose", Required = false)]
        [BooleanValidator()]
        public bool VerboseOutput
        {
            get { return verboseoutput; }
            set { verboseoutput = value; }
        }

        #endregion

        /// <summary>
        /// Initialize command
        /// </summary>
        protected override void InitializeSVNTask()
        {
            Command = SVNCommands.LOG;
            Options.Add(SVNFlags.LIMIT);
            Options.Add(Limit.ToString());
            if (MergeInfoOutput) Options.Add(SVNFlags.MERGEINFO);
            if (VerboseOutput) Options.Add(SVNFlags.VERBOSE);
            Options.Add(SVNFlags.XMLOUTPUT);
        }

        /// <summary>
        /// Run the task
        /// </summary>
        protected override void ExecuteTask()
        {
            //First run the base task
            base.ExecuteTask();
            //Process the xml
            PropertiesManager.SetSVNProperty(Resources.PropertyNames.LogOutput, Output);
        }
    }
}
